package problem0063

import (
	"fmt"

	"github.com/zhwei820/gconv"
)

func main() {
	res := bullets([]int{1, 2, 2})

	// var a int
	// fmt.Scan(&a)
	fmt.Printf("%v", res)
}

func bullets(nums []int) (res []int) {
	if len(nums) == 1 {
		return []int{1}
	}

	var arr = make([][]int, 2*104)
	asc := false
	kk := 0
	arr[0] = []int{nums[0]}
	for jj := 1; jj < len(nums); jj++ {
		if nums[jj-1] > nums[jj] && asc {
			kk++
			asc = false
		} else if nums[jj-1] < nums[jj] && !asc {
			kk++
			asc = true
		}
		fmt.Println("kk", kk)
		arr[kk] = append(arr[kk], nums[jj])
	}
	fmt.Println("arr", gconv.Export(arr))

	k := 0
	asc = false
	for _, item := range arr {
		if len(item) == 0 {
			continue
		}
		ll := len(item)
		if ll > 1 && item[0] < item[ll-1] {
			asc = true
			if k == 0 {
				k = 1
			}
		} else {
			asc = false
			if k == 0 {
				k = len(item)
			} else {
				k += 1
			}
		}
		fmt.Println("item", gconv.Export(item))
		for _, _ = range item {
			res = append(res, k)
			if asc {
				k++
			} else {
				k--
			}
			if k == 0 {
				k = 1
			}
		}
	}
	fmt.Println("res", gconv.Export(res))

	return res
}
